package com.orangelife.mobile.login.biz;

import android.content.Context;

import com.curry.android.util.StringUtil;
import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.constants.Constant;
import com.orangelife.mobile.util.CryptoDES;
import com.orangelife.mobile.util.ToastHelper;

/**
 * Created by wgf on 2016/3/30.
 *
 * @author wgf
 * @since 3.6.0
 */
public class LoginBiz {

    public static boolean validatePhoneNum(String phoneNum, Context context) {
        if (StringUtil.isContainBlank(phoneNum)) {/*判空*/
            ToastHelper.getInstance().displayToastWithQuickClose(
                    context.getResources().getString(
                            R.string.tip_input_phone_num));
            return false;
        } else if (phoneNum.length() != 11) {/*位数*/
            ToastHelper.getInstance().displayToastWithQuickClose(
                    context.getResources().getString(
                            R.string.register_phone_error));
            return false;
        }
        return true;
    }

    public static boolean validatePassword(String password, boolean isUsePassword) {
        String message;
        if (isUsePassword) {
            message = "登录密码不能为空";
        } else {
            message = "短信验证码不能为空";
        }
        if (StringUtil.isContainBlank(password)) {
            ToastHelper.getInstance()._toast(message);
            return false;
        }
        return true;
    }

    public static String encryptPhone(String phone) {
        try {
            phone = CryptoDES.encrypt(phone, Constant.DES_KEY);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return phone;
    }

    public static String encryptPassword(String password) {
        return StringUtil.md5(password);
    }
}
